// pages/search/search.js
const app =getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    post:{
      keyword: ''
    },
    niusearch: [],
    history: true,   //是否展示历史
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: ((res.windowHeight * 750) / res.windowWidth)
        })
      }
    });
    let niuserach = app.getSearch('niusearch');
    this.setData({
      niusearch: niuserach
    });
  },
  seachkeyword(event) {
    let { value } = event.detail;
   
    this.setData({
      ['post.keyword']: value
    })
  },
  tosearch(e) {
    let keyword = e.currentTarget.dataset.keyword;
    this.setData({
      ['post.keyword']: keyword
    })
    app.saveSearch(keyword, 'niusearch');

    this.toSearch();
  },
  search() {
   
    this.toSearch();
  },
  clickSearch() {
    
    this.toSearch();
  },
  toSearch() {
    this.setData({
      history: false
    })
    this.selectComponent('.scroll').refresh();
  },

  refresh(res) {
    let data = res.detail.data.data;
    this.data.list = data;
    this.setData({
      list: this.data.list
    });
  },
  more(res) {
    let data = res.detail.data.data;
    this.data.list.push(...data);
    this.setData({
      data: data
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.selectComponent('.scroll').more();
  },
})